# 作者: 家里蹲 吴越洋
# 2023年03月02日19时59分51秒
from operator import itemgetter,attrgetter

a = [51, 10, 26, 8, 9, 44]
print(sorted(a))
print(a)

dict = {1: "tianitan", 5: "xiaotian", 3: "zhangsan", 4: "lisi", 2: "wangwu"}
print(sorted(dict))
print(dict)

print('-' * 50)
print(sorted("This is a test string from Andrew".split(), key=str.lower))

student_tuple=[
    ('zhangsan', 'A', 15),
    ('lisi', 'B', 18),
    ('wangwu', 'B', 10),
]
def student_name(data):
    return data[2]
print(sorted(student_tuple,key=student_name))
print(sorted(student_tuple,key=lambda student:student[2]))
print(sorted(student_tuple,key=itemgetter(1,2))) # 列表排序

class Student:
    def __init__(self,name,grade,age):
        self.name=name
        self.grade=grade
        self.age=age

    def __repr__(self):
        return  repr((self.name,self.grade,self.age))

student_objects = [
    Student('john', 'A', 15),
    Student('jane', 'B', 12),
    Student('dave', 'B', 10),
    ]

print(sorted(student_objects,key=lambda student:student.name))
print(sorted(student_objects,key=attrgetter('age')))  # attrgeter对象属性排序，不支持切片